home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / SNNSV32.ZIP / SNNSv3.2 / xgui / sources / ui_display.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-04-25  |  8.3 KB  |  321 lines

  1. /*****************************************************************************
  2.   FILE           : ui_display.c
  3.   SHORTNAME      : display.c
  4.   SNNS VERSION   : 3.2
  5.  
  6.   PURPOSE        : contains routines to handle the list of all network displays
  7.   NOTES          :
  8.  
  9.   AUTHOR         : Tilman Sommer
  10.   DATE           : 26.7.1990
  11.  
  12.   CHANGED BY     :
  13.  
  14.   IDENTIFICATION : @(#)ui_display.c    1.9 3/2/94
  15.   SCCS VERSION   : 1.9
  16.   LAST CHANGE    : 3/2/94
  17.  
  18.              Copyright (c) 1990-1994  SNNS Group, IPVR, Univ. Stuttgart, FRG
  19.  
  20. ******************************************************************************/
  21.  
  22. #include <stdio.h>
  23. #include <stdlib.h>
  24.  
  25. #include "ui.h"
  26. #include "ui_utilP.h"
  27. #include "ui_funcdispl.h"
  28. #include "ui_netUpdate.h"
  29. #include "ui_setupP.h"
  30. #include "ui_setup.h"
  31. #include "ui_mainP.h"
  32.  
  33. #include "ui_display.ph"   /* private include-file */
  34.  
  35.  
  36. /*****************************************************************************
  37.   FUNCTION : ui_displ_createItem
  38.  
  39.   PURPOSE  : allocate size for one item from the heap and set default values
  40.   RETURNS  : pointer to that new item
  41.   NOTES       :
  42.  
  43.   UPDATES  :
  44. *****************************************************************************/
  45.  
  46. static struct Ui_DisplayType *ui_displ_createItem(void)
  47.  
  48. {
  49.     struct Ui_DisplayType  *displPtr;
  50.  
  51.     displPtr = (struct Ui_DisplayType *) malloc(sizeof(struct Ui_DisplayType));
  52.     if (displPtr != NULL) {
  53.     (*displPtr).x            = 1;
  54.     (*displPtr).y            = 1;
  55.     (*displPtr).origin.x     = 0;
  56.     (*displPtr).origin.y     = 0;
  57.     (*displPtr).width        = 450;
  58.     (*displPtr).height       = 300;
  59.     (*displPtr).gridSize     = 37;
  60.     (*displPtr).unitsInX     = (*displPtr).width  / (*displPtr).gridSize;
  61.     (*displPtr).unitsInY     = (*displPtr).height / (*displPtr).gridSize;
  62.     (*displPtr).frozen       = FALSE;
  63.     (*displPtr).subNetNo     = 0;
  64.     (*displPtr).layers       = 1;
  65.     ui_set_initData(displPtr);
  66.     (*displPtr).updateType   = UI_INTELLIGENT;
  67.     (*displPtr).flags        = UI_CLOSED + 1; /*!*/ /* mapped */
  68.     (*displPtr).nextPtr      = NULL;
  69.     (*displPtr).displayNo    = ui_displ_numberOfItems;
  70.     }
  71.     return (displPtr);
  72. }
  73.  
  74.  
  75. /*****************************************************************************
  76.   FUNCTION : ui_displ_initDisplayList
  77.  
  78.   PURPOSE  : initialize the Display list and Display counters
  79.   RETURNS  : void
  80.   NOTES       :
  81.  
  82.   UPDATES  :
  83. *****************************************************************************/
  84.  
  85. void ui_displ_initDisplayList(void)
  86.  
  87. {
  88.     ui_displ_numberOfItems          = 1;
  89.     ui_displ_listPtr                = NULL;
  90.     ui_displ_freeListPtr            = ui_displ_createItem();
  91.     ui_currentDisplay               = ui_displ_listPtr;
  92.     ui_displ_numberOfItems          = 0;
  93. }
  94.  
  95.  
  96. /*****************************************************************************
  97.   FUNCTION : ui_displ_resetList  
  98.  
  99.   PURPOSE  : links all items in the free list and closes the displays 
  100.   RETURNS  : void
  101.   NOTES    :
  102.  
  103.   UPDATE   :
  104. *****************************************************************************/
  105.  
  106. void ui_displ_resetList(void)
  107.  
  108. {
  109.     struct Ui_DisplayType  *displPtr;
  110.  
  111.     while (ui_displ_listPtr != NULL) {
  112.     displPtr = ui_displ_listPtr;
  113.     ui_displayDone(NULL, displPtr, NULL);
  114.     /* ui_displ_freeItem() is performed in ui_displayDone() ! */
  115.     }
  116. }
  117.  
  118.     
  119. /*****************************************************************************
  120.   FUNCTION : ui_displ_freeItem
  121.  
  122.   PURPOSE  : links the item in the free list
  123.   RETURNS  : void
  124.   NOTES    :
  125.  
  126.   UPDATES  :
  127. *****************************************************************************/
  128.  
  129. void ui_displ_freeItem(struct Ui_DisplayType *displayPtr)
  130.  
  131. {
  132.     struct Ui_DisplayType  *displPtr;
  133.  
  134.     if (ui_displ_listPtr == displayPtr) { /* is first element */
  135.     ui_displ_listPtr     = displayPtr->nextPtr;
  136.     displayPtr->nextPtr  = ui_displ_freeListPtr;
  137.     ui_displ_freeListPtr = displayPtr;
  138.     ui_displ_numberOfItems -= 1;
  139.     } else { /* second, third, ... element */
  140.     displPtr = ui_displ_listPtr;
  141.     while ((displPtr->nextPtr != displayPtr) AND
  142.            (displPtr->nextPtr != NULL)) 
  143.         displPtr = displPtr->nextPtr;
  144.  
  145.     if (displPtr->nextPtr == displayPtr) { /* item was found */
  146.         displPtr->nextPtr    = displayPtr->nextPtr;
  147.         displayPtr->nextPtr  = ui_displ_freeListPtr;
  148.         ui_displ_freeListPtr = displayPtr;
  149.         ui_displ_numberOfItems -= 1;
  150.     }
  151.     }
  152. }
  153.     
  154.  
  155. /*****************************************************************************
  156.   FUNCTION : Ui_DisplayType
  157.  
  158.   PURPOSE  : looks in the free list for an item. If no one is found, 
  159.              ui_displ_createItem() is called to create a new one.
  160.   RETURNS  : a pointer to a free item or NULL if malloc() fails
  161.   NOTES    :
  162.  
  163.   UPDATES  :
  164. *****************************************************************************/
  165.  
  166. struct Ui_DisplayType *ui_displ_getFreeItem(void)
  167.  
  168. {
  169.     struct Ui_DisplayType  *displPtr;
  170.  
  171.     ui_displ_numberOfItems++;
  172.     if (ui_displ_freeListPtr == NULL) { /* no free item */
  173.     displPtr             = ui_displ_createItem(); /* create a new item */
  174.     } else {
  175.     displPtr             = ui_displ_freeListPtr;
  176.     ui_displ_freeListPtr = displPtr->nextPtr;
  177.     }
  178.     if (displPtr != NULL) {
  179.     /* link it in the list as the first element */
  180.     (*displPtr).nextPtr = ui_displ_listPtr;
  181.     ui_displ_listPtr    = displPtr;
  182.     }
  183.     return(displPtr);
  184. }
  185.     
  186.  
  187. #ifdef _UNUSED_FUNCTIONS_
  188.  
  189. /*****************************************************************************
  190.   FUNCTION : ui_displ_getDisplayPtrViaDrawable
  191.  
  192.   PURPOSE  : search through the display list for a display with the specified
  193.              drawable ID
  194.   RETURNS  : struct Ui_DisplayType
  195.   NOTES    : !!! function is not used yet
  196.  
  197.   UPDATE   : 1.2.1990
  198. ******************************************************************************/
  199.  
  200. /*!*/ /* not used */
  201. static struct Ui_DisplayType *ui_displ_getDisplayPtrViaDrawable(Widget w)
  202.  
  203.  
  204. {
  205.     struct Ui_DisplayType *dPtr;
  206.  
  207.     dPtr = ui_displ_listPtr;
  208.     while((dPtr != NULL) AND (dPtr->widget != w))
  209.     dPtr = dPtr->nextPtr;
  210.  
  211.     return(dPtr);
  212. }
  213.  
  214. #endif  /*  _UNUSED_FUNCTIONS_ */
  215.  
  216.  
  217. #ifdef _UNUSED_FUNCTIONS_
  218.  
  219. /*****************************************************************************
  220.   FUNCTION : ui_displ_getDisplayPtrViaFrameWidget
  221.  
  222.   PURPOSE  : search through the display list for a display with the specified
  223.              frame widget
  224.   RETURNS  : struct Ui_DisplayType
  225.   NOTES    : !!! function is not used yet
  226.  
  227.   UPDATE   : 1.2.1990
  228. ******************************************************************************/
  229.  
  230. /*!*/ /* not used */
  231. static struct Ui_DisplayType *ui_displ_getDisplayPtrViaFrameWidget(Widget w)
  232.  
  233. {
  234.     struct Ui_DisplayType *dPtr;
  235.  
  236.     dPtr = ui_displ_listPtr;
  237.     while((dPtr != NULL) AND (dPtr->frameWidget != w))
  238.     dPtr = dPtr->nextPtr;
  239.  
  240.     return(dPtr);
  241. }
  242.  
  243. #endif /*  _UNUSED_FUNCTIONS_ */
  244.  
  245.  
  246. /*****************************************************************************
  247.   FUNCTION : ui_displ_isSomeWhereToShowWeights
  248.  
  249.   PURPOSE  : Returns TRUE if there is to show the weights of links 
  250.              in any display.
  251.   RETURNS  : Bool
  252.   NOTES    :
  253.  
  254.   UPDATE   : 1.2.1990
  255. ******************************************************************************/
  256.  
  257. Bool ui_displ_isSomeWhereToShowWeights(void)
  258.  
  259. {
  260.     struct Ui_DisplayType *dPtr;
  261.  
  262.     dPtr = ui_displ_listPtr;
  263.     while((dPtr != NULL)) {
  264.     if (dPtr->setup.showWeightFlg) return(TRUE);
  265.     dPtr = dPtr->nextPtr;
  266.     }
  267.     return(FALSE);
  268. }
  269.  
  270.  
  271. /*****************************************************************************
  272.   FUNCTION : ui_displ_isSomeWhereToShowValues
  273.  
  274.   PURPOSE  : Returns TRUE if there is to show the unit value numerically 
  275.              in any display.
  276.   RETURNS  : Bool
  277.   NOTES    :
  278.  
  279.   UPDATE   : 1.2.1990
  280. ******************************************************************************/
  281.  
  282. Bool ui_displ_isSomeWhereToShowValues(void)
  283.  
  284. {
  285.     struct Ui_DisplayType *dPtr;
  286.  
  287.     dPtr = ui_displ_listPtr;
  288.     while((dPtr != NULL)) {
  289.     if (dPtr->setup.showValueFlg) return(TRUE);
  290.     dPtr = dPtr->nextPtr;
  291.     }
  292.     return(FALSE);
  293. }
  294.  
  295.  
  296. /*****************************************************************************
  297.   FUNCTION : ui_displ_freezeDisplay
  298.  
  299.   PURPOSE  : sets the freeze flag in the display structure
  300.   RETURNS  : void
  301.   NOTES    : 
  302.  
  303.   UPDATES  :
  304. *****************************************************************************/
  305.  
  306. void ui_displ_freezeDisplay(Widget w, struct Ui_DisplayType *displayPtr, 
  307.                 caddr_t call_data)
  308.  
  309. {
  310.     displayPtr->frozen = NOT displayPtr->frozen;
  311.     ui_net_completeRefresh(displayPtr, UI_LOCAL);
  312. }
  313.  
  314.  
  315.  
  316.  
  317.  
  318.  
  319. /* end of file */
  320. /* lines: 301 */
  321.